< previous page page_986 next page >

Page 986
Now build the following procedure to perform the posting:
Public Sub Post()

    On Error GoTo PostErr

    Dim cSQL As String

    wsUpdate.BeginTrans

    'Create the SQL statement to insert the records.
    _'Note that we do not use the TransNo field
    _'as it is a counter field necessary only
    _'for the Transactions table
    cSQL = "INSERT INTO History Select CustID, InvoiceNo,
    _Amount FROM Transactions"
    DB.Execute cSQL

    'Delete the temporary transactions data
    cSQL = "DELETE FROM Transactions"
    DB.Execute cSQL

    'Commit the transactions
    wsUpdate.CommitTrans
    MsgBox "Transactions have been committed"

    'Set the error flag and exit the program
    nErrFlag = 0
    GoTo PostExit

PostErr:
    'Display the error and rollback the transactions
    MsgBox Trim(Str(Err)) + " " + Error$(Err), vbCritical, "Post"
    wsUpdate.Rollback
    MsgBox "Post routine has been aborted"

PostExit:

End Sub
Finally, insert the following code into the cmdPost_Click event:
Private Sub cmdPost_Click()

    OpenDB
    If nErrFlag = 0 Then
        Post
    End If

    If nErrFlag <> 0 Then
        MsgBox "Error Reported", vbCritical, "cmdPost"
    End If

    Unload Me

End Sub
You can test this program by building the database in Visdata or Data Manager and then inserting some sample records into the Transactions table.

 
< previous page page_986 next page >

If you like this book, buy it!